package org.ztr.yanai.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.ztr.yanai.blog.entity.Category;
import org.ztr.yanai.blog.mapper.CategoryMapper;
import org.ztr.yanai.blog.service.CategoryService;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/11/22 10:00
 * @Description: 分类服务实现类
 * @Version: 1.0
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    private final CategoryMapper categoryMapper;

    public CategoryServiceImpl(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    @Override
    public boolean createCategory(Category category) {
        return categoryMapper.insert(category) > 0;
    }

    @Override
    public boolean deleteCategoryById(Long id) {
        return categoryMapper.deleteById(id) > 0;
    }

    @Override
    public Category getCategoryById(Long id) {
        return categoryMapper.selectById(id);
    }

    @Override
    public Page<Category> listCategoriesByPage(int pageNum, int pageSize, QueryWrapper<Category> wrapper) {
        Page<Category> page = new Page<>(pageNum, pageSize);
        return categoryMapper.selectPage(page, wrapper);
    }

    @Override
    public boolean updateCategory(Category category) {
        return categoryMapper.updateById(category) > 0;
    }
}
